package com.fitness.front.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fitness.front.convertor.CourseRateConvertor;
import com.fitness.front.mapper.CourseRateMapper;
import com.fitness.front.modal.course.dto.CourseRateDto;
import com.fitness.front.modal.course.entity.CourseRate;
import com.fitness.front.service.ICourseRateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class CourseRateServiceImpl extends ServiceImpl<CourseRateMapper,CourseRate> implements ICourseRateService {

    private final CourseRateConvertor courseRateConvertor;

    @Override
    public boolean addCourseRate(CourseRateDto courseRateDto) {
        return this.baseMapper.insert(courseRateConvertor.dto2Entity(courseRateDto)) > 0;
    }

    @Override
    public CourseRate getCourseRate(Long userId, Long courseId) {
        return lambdaQuery().eq(CourseRate::getUserId, userId).and(q -> q.eq(CourseRate::getCourseId, courseId)).one();
    }
}
